function createSlice(options) {
  // 解构取值
  const { name, initialState, reducers } = options;

  // 取出 reducers 中的 key
  const keys = Object.keys(reducers); // ['increment', 'decrement']

  // 得到一个 actions
  let actions = {};
  keys.forEach((key) => {
    // actions[key] 是一个动作创建函数
    actions[key] = (payload) => {
      return {
        type: `${name}/${key}`,
        payload: payload,
      };
    };
  });

  return { actions };
}

const obj = createSlice({
  name: "counter",
  reducers: {
    increment(state, action) {
      state.count++;
    },
    decrement(state, action) {
      state.count--;
    },
  },
});

console.log(obj.actions.increment(1));
